package com.ice.work.moment.crawler.service.impl;

import com.honeybee.cloud.framework.base.exception.business.BaseBizException;
import com.ice.work.moment.crawler.dao.position.institutional.InstitutionalPositionRepository;
import com.ice.work.moment.crawler.service.IInstitutionalPositionService;
import com.ice.work.moment.facade.crawler.model.InstitutionalPosition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Objects;

/**
 * @Description 机构持仓信息
 * @Author DELL
 * @Create 2019-05-05
 * @Since 1.0.0
 */
@SuppressWarnings("unused")
@Component
public class InstitutionalPositionServiceImpl implements IInstitutionalPositionService {

    @Autowired
    private InstitutionalPositionRepository positionRepository;


    @Override
    public Boolean saveOrUpdate(InstitutionalPosition item) throws BaseBizException {
        Assert.notNull(item, "item not null");
        InstitutionalPosition exists = positionRepository.findByInstitutionalPositionTypeIdAndStockIdAndCloseAtDataStatus(item);
        if (Objects.nonNull(exists)) {
            item.setId(exists.getId());
        }
        return positionRepository.saveOrUpdate(item);
    }
}
